//index.js
//获取应用实例
var app = getApp();
//console.log(app.globalData);
Page({
  data: {
    userInfo: {},
    region: [],
    data:{},
    customItem: '全部',
    status: 0,
    location: '',
    address: '',
    id: 0,
    store_id: 0,
    community_name: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options.id) {
      this.data.id = options.id;
      this.init();
    }
  },
  bindDateChange: function (e) {
    var v = e.detail.value;
    var name = e.currentTarget.dataset.name;
    var data = this.data.data;
    data.addtime=v;
    this.setData({ data: data });
    // this.datedifference();

  },
  // onShow: function () {
  //   var id = app.getPageData("index/issue", "id");
  //   if (id) {
  //     this.data.id = id;
  //     this.init();
  //     app.setPageData("index/issue", { id: 0 });
  //   }
  // },
  init: function () {
    var that = this;
    app.api("api/community_houses/find", {
      id: this.data.id,
    }, function (res) {
      that.data.loading = 0;
      if (res.code != 200) {
        app.alert(res.msg);
        return;
      }
      //var poi = res.data.community_locations.split("|")
      that.setData({
        data: res.data,
      });
    })
  },

  formSubmit: function (e) {
    var postData = e.detail.value;
    if (postData.out_room_id == "") {
      app.alert("请输小区房屋唯一编号");
      return false;
    }
    if (postData.name == "") {
      app.alert("请输入姓名");
      return false;
    }
    if (postData.phone == "") {
      app.alert("请输入手机号");
      return false;
    }
     

    var that = this;
    that.setData({ 'loading': 1 });
    that.setData({ 'disabled': 1 });
    app.api("api/community_houses/add", {
      method: 'POST',
      id: this.data.id ? this.data.id :"",
      out_room_id:  postData.out_room_id,
      name: postData.name,
      tel: postData.tel,
      phone: postData.phone,
      addtime: this.data.data.addtime,
      //out_room_id: postData.out_room_id,

    }, function (res) {
      if (res.code != 200) {
        app.alert(res.msg);
        that.data.payloading = 0;
        that.setData({ 'loading': 0 });
        that.setData({ 'disabled': 0 });
        return false;
      }
      // that.reset();
      wx.showToast({
        title: '保存成功',
        icon: 'success',
        duration: 2000
      })
      app.setPageData("tenement/houses", { reload: 1 });
      wx.navigateBack();
    })

  }


})
